#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int sum, ret;
    int findTargetSumWays(vector<int>& nums, int target)
    {
        dfs(nums, 0, target);
        return ret;
    }

    void dfs(vector<int>& nums, int pos, int target)
    {
        if (pos == nums.size())
        {
            if (sum == target)ret++;
            return;
        }
        for (int i = 0; i < 2; i++)
        {
            if (i == 0) sum += nums[pos];
            else sum -= nums[pos];


            dfs(nums, pos + 1, target);
            if (i == 0) sum -= nums[pos];
            else sum += nums[pos];
        }
        return;

    }
};